package com.ruoyi.web.controller.his;

import java.util.List;

import com.ruoyi.his.domain.HisTeamGroup;
import com.ruoyi.his.service.IHisTeamGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.his.domain.HisWorkShift;
import com.ruoyi.his.service.IHisWorkShiftService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作班次Controller
 * 
 * @author tsenlem
 * @date 2023-11-02
 */
@Controller
@RequestMapping("/his/shift")
public class HisWorkShiftController extends BaseController
{
    private String prefix = "his/shift";

    @Autowired
    private IHisWorkShiftService hisWorkShiftService;

    @Autowired
    private IHisTeamGroupService teamGroupService;

    @RequiresPermissions("his:shift:view")
    @GetMapping()
    public String shift(ModelMap map)
    {
        HisTeamGroup team = new HisTeamGroup();
        team.setStatus("E");
        List<HisTeamGroup> list = teamGroupService.selectHisTeamGroupList(team);
        map.put("list", list);
        return prefix + "/shift";
    }

    /**
     * 查询工作班次列表
     */
    @RequiresPermissions("his:shift:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HisWorkShift hisWorkShift)
    {
        startPage();
        List<HisWorkShift> list = hisWorkShiftService.selectHisWorkShiftList(hisWorkShift);
        return getDataTable(list);
    }

    /**
     * 导出工作班次列表
     */
    @RequiresPermissions("his:shift:export")
    @Log(title = "工作班次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HisWorkShift hisWorkShift)
    {
        List<HisWorkShift> list = hisWorkShiftService.selectHisWorkShiftList(hisWorkShift);
        ExcelUtil<HisWorkShift> util = new ExcelUtil<HisWorkShift>(HisWorkShift.class);
        return util.exportExcel(list, "工作班次数据");
    }

    /**
     * 新增工作班次
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工作班次
     */
    @RequiresPermissions("his:shift:add")
    @Log(title = "工作班次", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HisWorkShift hisWorkShift)
    {
        hisWorkShift.setCreateBy(getLoginName());
        return toAjax(hisWorkShiftService.insertHisWorkShift(hisWorkShift));
    }

    /**
     * 修改工作班次
     */
    @RequiresPermissions("his:shift:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        HisWorkShift hisWorkShift = hisWorkShiftService.selectHisWorkShiftById(id);
        mmap.put("hisWorkShift", hisWorkShift);
        return prefix + "/edit";
    }

    /**
     * 修改保存工作班次
     */
    @RequiresPermissions("his:shift:edit")
    @Log(title = "工作班次", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HisWorkShift hisWorkShift)
    {
        return toAjax(hisWorkShiftService.updateHisWorkShift(hisWorkShift));
    }

    /**
     * 删除工作班次
     */
    @RequiresPermissions("his:shift:remove")
    @Log(title = "工作班次", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hisWorkShiftService.deleteHisWorkShiftByIds(ids));
    }
}
